home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostscript / src / astate.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  109 lines

  1. /* Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* astate.h */
  20. /* State structures for the Ghostscript allocator */
  21.  
  22. /* Define pointers to an allocation state. */
  23. /****** Note the _ds (for Turbo C only). ******/
  24. typedef struct alloc_state_s alloc_state;
  25. typedef alloc_state _ds *alloc_state_ptr;
  26. /* The only instance.... */
  27. extern alloc_state_ptr alloc_state_current;
  28.  
  29. /* Round up sizes of aligned objects. */
  30. #define log2_align_mod 3        /* log2(sizeof(double)) */
  31. #define align_mod (1<<log2_align_mod)
  32. #define align_mask (align_mod-1)
  33. #define align_round(siz) (uint)(((siz) + align_mask) & -align_mod)
  34.  
  35. /* Max object size for separate free list. */
  36. /* We want this to be big enough to handle a gstate_contents, */
  37. /* which is currently 342 bytes. */
  38. #define max_chain_size 350
  39.  
  40. /* Structure for a separately allocated block. */
  41. typedef struct alloc_block_s alloc_block;
  42. struct alloc_block_s {
  43.     alloc_block *next;
  44.     uint size;
  45.     int save_level;
  46.     alloc_state_ptr cap;
  47. };
  48. #define alloc_block_size align_round(sizeof(alloc_block))
  49.  
  50. /* Structure for a single wholesale allocation 'chunk'. */
  51. typedef struct alloc_chunk_s alloc_chunk;
  52. struct alloc_chunk_s {
  53.     /* Note that allocation takes place both from the bottom up */
  54.     /* (aligned objects) and from the top down (byte objects). */
  55.     byte *base;
  56.     byte *bot;            /* bottom of free area */
  57.                     /* (top of aligned objects) */
  58.     byte *top;            /* top of free area */
  59.                     /* (bottom of byte objects) */
  60.     byte *limit;
  61.     int save_level;            /* save level when this chunk */
  62.                     /* was allocated */
  63.     alloc_chunk *next;        /* chain chunks together */
  64. };
  65.  
  66. #define ptr_is_in_chunk(ptr, chunk)\
  67.   ptr_between(ptr, (chunk)->base, (chunk)->limit)
  68.  
  69. /* Structures for save/restore (not defined here). */
  70. struct alloc_save_s;
  71. struct alloc_change_s;
  72.  
  73. /* Structure for allocator state.  If we multi-thread some day, */
  74. /* this might be instantiated more than once. */
  75. struct alloc_state_s {
  76.     alloc_chunk current;        /* the current chunk */
  77. #define cbase current.base
  78. #define cbot current.bot
  79. #define ctop current.top
  80. #define climit current.limit
  81.     alloc_chunk *current_ptr;    /* where to put current */
  82.     uint chunk_size;        /* unit for wholesale malloc */
  83.     uint big_size;            /* min size for separate malloc */
  84.     const gs_memory_procs *mprocs;    /* procs for separate malloc/free */
  85.     alloc_chunk *last_freed;    /* cache the last non-current chunk */
  86.                     /* at the current save level */
  87.                     /* where we freed an object */
  88.     uint local_attr;        /* 0 if global VM, a_local if local */
  89.     /* Statistics */
  90.     long used;            /* total space used, including */
  91.                     /* malloc'ed blocks and all chunks */
  92.                     /* other than the current one */
  93.     long total;            /* total space allocated, */
  94.                     /* other than malloc'ed blocks */
  95.     unsigned num_chunks;
  96.     /* Chain together freed objects within a save level. */
  97.     /* We only do this for aligned objects. */
  98. #define num_free_chains ((max_chain_size >> log2_align_mod) + 1)
  99.     char *free[num_free_chains];
  100.     /* Chain together any malloc'ed objects */
  101.     alloc_block *malloc_chain;
  102.     /* Keep track of saved states */
  103.     int save_level;
  104.     struct alloc_save_s *saved;
  105.     byte *saved_cbot;        /* cbot at last save */
  106.     byte *saved_ctop;        /* ctop at last save */
  107.     struct alloc_change_s *changes;
  108. };
  109.